using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using System.Xml;
using System.Globalization;
using System.Threading;

namespace CrateManiaPipeline
{
    [ContentImporter(".tsx", DisplayName = "Tiled tileset Importer", DefaultProcessor = "TilesetProcessor")]
    public class TilesetImporter : ContentImporter<TilesetContent>
    {
        public override TilesetContent Import(string filename, ContentImporterContext context)
        {
            XmlDocument xd = new XmlDocument();
            xd.Load(filename);

            CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;
            try
            {
                // ensures all parsing is done using "C" locale
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                return new TilesetContent(xd.SelectSingleNode("tileset"), context);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
    }
}
